﻿using System;
using System.Security.Cryptography;
using System.Text;
using System.Web.Security;

namespace Matrix.Common.Utility
{
    /// <summary>
    /// MD5加密
    /// </summary>
    public class MD5Lib
    {
        /// <summary>
        /// 字符串MD5加密，返回大写字母
        /// </summary>
        /// <param name="plainText">明文</param>
        /// <returns>密文（大写字母）</returns>
        public static string Encrypt(string plainText)
        {
            MD5CryptoServiceProvider md = new MD5CryptoServiceProvider();
            byte[] b = md.ComputeHash(Encoding.Default.GetBytes(plainText));
            string s = String.Empty;
            for (int i = 0; i < b.Length; i++)
            {
                s += (b[i].ToString("x2"));
            }
            return s.ToUpper();
        }
    }
}